﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Rendering.SphericalHarmonicsL2
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using UnityEngine.Bindings;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine.Rendering
{
  /// <summary>
  ///   <para>Spherical harmonics up to the second order (3 bands, 9 coefficients).</para>
  /// </summary>
  [UsedByNativeCode]
  [NativeHeader("Runtime/Export/Math/SphericalHarmonicsL2.bindings.h")]
  public struct SphericalHarmonicsL2 : IEquatable<SphericalHarmonicsL2>
  {
    private float shr0;
    private float shr1;
    private float shr2;
    private float shr3;
    private float shr4;
    private float shr5;
    private float shr6;
    private float shr7;
    private float shr8;
    private float shg0;
    private float shg1;
    private float shg2;
    private float shg3;
    private float shg4;
    private float shg5;
    private float shg6;
    private float shg7;
    private float shg8;
    private float shb0;
    private float shb1;
    private float shb2;
    private float shb3;
    private float shb4;
    private float shb5;
    private float shb6;
    private float shb7;
    private float shb8;

    /// <summary>
    ///   <para>Clears the spherical harmonics coefficients to zero.</para>
    /// </summary>
    public void Clear() => this.SetZero();

    private void SetZero() => SphericalHarmonicsL2.SetZero_Injected(ref this);

    /// <summary>
    ///   <para>Add an ambient light to the spherical harmonics.</para>
    /// </summary>
    /// <param name="color"></param>
    public void AddAmbientLight(Color color)
    {
      SphericalHarmonicsL2.AddAmbientLight_Injected(ref this, ref color);
    }

    /// <summary>
    ///   <para>Add a directional light to the spherical harmonics.</para>
    /// </summary>
    /// <param name="direction">The direction from the light probe to the light. The vector should be normalized for correct results.</param>
    /// <param name="color">The color of the light.</param>
    /// <param name="intensity">The intensity of the light.</param>
    public void AddDirectionalLight(Vector3 direction, Color color, float intensity)
    {
      Color color1 = color * (2f * intensity);
      SphericalHarmonicsL2.AddDirectionalLightInternal(ref this, direction, color1);
    }

    [FreeFunction]
    private static void AddDirectionalLightInternal(
      ref SphericalHarmonicsL2 sh,
      Vector3 direction,
      Color color)
    {
      SphericalHarmonicsL2.AddDirectionalLightInternal_Injected(ref sh, ref direction, ref color);
    }

    /// <summary>
    ///   <para>Evaluates the spherical harmonics for each given direction. The directions and results arrays must have the same size.</para>
    /// </summary>
    /// <param name="directions">Array of normalized directions in which to evaluate the spherical harmonics.</param>
    /// <param name="results">Output array for the evaluated values. The order of the results is the same as the directions array.</param>
    public void Evaluate(Vector3[] directions, Color[] results)
    {
      if (directions == null)
        throw new ArgumentNullException(nameof (directions));
      if (results == null)
        throw new ArgumentNullException(nameof (results));
      if (directions.Length == 0)
        return;
      if (directions.Length != results.Length)
        throw new ArgumentException("Length of the directions array and the results array must match.");
      SphericalHarmonicsL2.EvaluateInternal(ref this, directions, results);
    }

    [FreeFunction]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void EvaluateInternal(
      ref SphericalHarmonicsL2 sh,
      Vector3[] directions,
      [Out] Color[] results);

    public float this[int rgb, int coefficient]
    {
      get
      {
        switch (rgb * 9 + coefficient)
        {
          case 0:
            return this.shr0;
          case 1:
            return this.shr1;
          case 2:
            return this.shr2;
          case 3:
            return this.shr3;
          case 4:
            return this.shr4;
          case 5:
            return this.shr5;
          case 6:
            return this.shr6;
          case 7:
            return this.shr7;
          case 8:
            return this.shr8;
          case 9:
            return this.shg0;
          case 10:
            return this.shg1;
          case 11:
            return this.shg2;
          case 12:
            return this.shg3;
          case 13:
            return this.shg4;
          case 14:
            return this.shg5;
          case 15:
            return this.shg6;
          case 16:
            return this.shg7;
          case 17:
            return this.shg8;
          case 18:
            return this.shb0;
          case 19:
            return this.shb1;
          case 20:
            return this.shb2;
          case 21:
            return this.shb3;
          case 22:
            return this.shb4;
          case 23:
            return this.shb5;
          case 24:
            return this.shb6;
          case 25:
            return this.shb7;
          case 26:
            return this.shb8;
          default:
            throw new IndexOutOfRangeException("Invalid index!");
        }
      }
      set
      {
        switch (rgb * 9 + coefficient)
        {
          case 0:
            this.shr0 = value;
            break;
          case 1:
            this.shr1 = value;
            break;
          case 2:
            this.shr2 = value;
            break;
          case 3:
            this.shr3 = value;
            break;
          case 4:
            this.shr4 = value;
            break;
          case 5:
            this.shr5 = value;
            break;
          case 6:
            this.shr6 = value;
            break;
          case 7:
            this.shr7 = value;
            break;
          case 8:
            this.shr8 = value;
            break;
          case 9:
            this.shg0 = value;
            break;
          case 10:
            this.shg1 = value;
            break;
          case 11:
            this.shg2 = value;
            break;
          case 12:
            this.shg3 = value;
            break;
          case 13:
            this.shg4 = value;
            break;
          case 14:
            this.shg5 = value;
            break;
          case 15:
            this.shg6 = value;
            break;
          case 16:
            this.shg7 = value;
            break;
          case 17:
            this.shg8 = value;
            break;
          case 18:
            this.shb0 = value;
            break;
          case 19:
            this.shb1 = value;
            break;
          case 20:
            this.shb2 = value;
            break;
          case 21:
            this.shb3 = value;
            break;
          case 22:
            this.shb4 = value;
            break;
          case 23:
            this.shb5 = value;
            break;
          case 24:
            this.shb6 = value;
            break;
          case 25:
            this.shb7 = value;
            break;
          case 26:
            this.shb8 = value;
            break;
          default:
            throw new IndexOutOfRangeException("Invalid index!");
        }
      }
    }

    public override int GetHashCode()
    {
      return ((((((((((((((((((((((((((17 * 23 + this.shr0.GetHashCode()) * 23 + this.shr1.GetHashCode()) * 23 + this.shr2.GetHashCode()) * 23 + this.shr3.GetHashCode()) * 23 + this.shr4.GetHashCode()) * 23 + this.shr5.GetHashCode()) * 23 + this.shr6.GetHashCode()) * 23 + this.shr7.GetHashCode()) * 23 + this.shr8.GetHashCode()) * 23 + this.shg0.GetHashCode()) * 23 + this.shg1.GetHashCode()) * 23 + this.shg2.GetHashCode()) * 23 + this.shg3.GetHashCode()) * 23 + this.shg4.GetHashCode()) * 23 + this.shg5.GetHashCode()) * 23 + this.shg6.GetHashCode()) * 23 + this.shg7.GetHashCode()) * 23 + this.shg8.GetHashCode()) * 23 + this.shb0.GetHashCode()) * 23 + this.shb1.GetHashCode()) * 23 + this.shb2.GetHashCode()) * 23 + this.shb3.GetHashCode()) * 23 + this.shb4.GetHashCode()) * 23 + this.shb5.GetHashCode()) * 23 + this.shb6.GetHashCode()) * 23 + this.shb7.GetHashCode()) * 23 + this.shb8.GetHashCode();
    }

    public override bool Equals(object other)
    {
      return other is SphericalHarmonicsL2 other1 && this.Equals(other1);
    }

    public bool Equals(SphericalHarmonicsL2 other) => this == other;

    public static SphericalHarmonicsL2 operator *(SphericalHarmonicsL2 lhs, float rhs)
    {
      return new SphericalHarmonicsL2()
      {
        shr0 = lhs.shr0 * rhs,
        shr1 = lhs.shr1 * rhs,
        shr2 = lhs.shr2 * rhs,
        shr3 = lhs.shr3 * rhs,
        shr4 = lhs.shr4 * rhs,
        shr5 = lhs.shr5 * rhs,
        shr6 = lhs.shr6 * rhs,
        shr7 = lhs.shr7 * rhs,
        shr8 = lhs.shr8 * rhs,
        shg0 = lhs.shg0 * rhs,
        shg1 = lhs.shg1 * rhs,
        shg2 = lhs.shg2 * rhs,
        shg3 = lhs.shg3 * rhs,
        shg4 = lhs.shg4 * rhs,
        shg5 = lhs.shg5 * rhs,
        shg6 = lhs.shg6 * rhs,
        shg7 = lhs.shg7 * rhs,
        shg8 = lhs.shg8 * rhs,
        shb0 = lhs.shb0 * rhs,
        shb1 = lhs.shb1 * rhs,
        shb2 = lhs.shb2 * rhs,
        shb3 = lhs.shb3 * rhs,
        shb4 = lhs.shb4 * rhs,
        shb5 = lhs.shb5 * rhs,
        shb6 = lhs.shb6 * rhs,
        shb7 = lhs.shb7 * rhs,
        shb8 = lhs.shb8 * rhs
      };
    }

    public static SphericalHarmonicsL2 operator *(float lhs, SphericalHarmonicsL2 rhs)
    {
      return new SphericalHarmonicsL2()
      {
        shr0 = rhs.shr0 * lhs,
        shr1 = rhs.shr1 * lhs,
        shr2 = rhs.shr2 * lhs,
        shr3 = rhs.shr3 * lhs,
        shr4 = rhs.shr4 * lhs,
        shr5 = rhs.shr5 * lhs,
        shr6 = rhs.shr6 * lhs,
        shr7 = rhs.shr7 * lhs,
        shr8 = rhs.shr8 * lhs,
        shg0 = rhs.shg0 * lhs,
        shg1 = rhs.shg1 * lhs,
        shg2 = rhs.shg2 * lhs,
        shg3 = rhs.shg3 * lhs,
        shg4 = rhs.shg4 * lhs,
        shg5 = rhs.shg5 * lhs,
        shg6 = rhs.shg6 * lhs,
        shg7 = rhs.shg7 * lhs,
        shg8 = rhs.shg8 * lhs,
        shb0 = rhs.shb0 * lhs,
        shb1 = rhs.shb1 * lhs,
        shb2 = rhs.shb2 * lhs,
        shb3 = rhs.shb3 * lhs,
        shb4 = rhs.shb4 * lhs,
        shb5 = rhs.shb5 * lhs,
        shb6 = rhs.shb6 * lhs,
        shb7 = rhs.shb7 * lhs,
        shb8 = rhs.shb8 * lhs
      };
    }

    public static SphericalHarmonicsL2 operator +(
      SphericalHarmonicsL2 lhs,
      SphericalHarmonicsL2 rhs)
    {
      return new SphericalHarmonicsL2()
      {
        shr0 = lhs.shr0 + rhs.shr0,
        shr1 = lhs.shr1 + rhs.shr1,
        shr2 = lhs.shr2 + rhs.shr2,
        shr3 = lhs.shr3 + rhs.shr3,
        shr4 = lhs.shr4 + rhs.shr4,
        shr5 = lhs.shr5 + rhs.shr5,
        shr6 = lhs.shr6 + rhs.shr6,
        shr7 = lhs.shr7 + rhs.shr7,
        shr8 = lhs.shr8 + rhs.shr8,
        shg0 = lhs.shg0 + rhs.shg0,
        shg1 = lhs.shg1 + rhs.shg1,
        shg2 = lhs.shg2 + rhs.shg2,
        shg3 = lhs.shg3 + rhs.shg3,
        shg4 = lhs.shg4 + rhs.shg4,
        shg5 = lhs.shg5 + rhs.shg5,
        shg6 = lhs.shg6 + rhs.shg6,
        shg7 = lhs.shg7 + rhs.shg7,
        shg8 = lhs.shg8 + rhs.shg8,
        shb0 = lhs.shb0 + rhs.shb0,
        shb1 = lhs.shb1 + rhs.shb1,
        shb2 = lhs.shb2 + rhs.shb2,
        shb3 = lhs.shb3 + rhs.shb3,
        shb4 = lhs.shb4 + rhs.shb4,
        shb5 = lhs.shb5 + rhs.shb5,
        shb6 = lhs.shb6 + rhs.shb6,
        shb7 = lhs.shb7 + rhs.shb7,
        shb8 = lhs.shb8 + rhs.shb8
      };
    }

    public static bool operator ==(SphericalHarmonicsL2 lhs, SphericalHarmonicsL2 rhs)
    {
      return (double) lhs.shr0 == (double) rhs.shr0 && (double) lhs.shr1 == (double) rhs.shr1 && (double) lhs.shr2 == (double) rhs.shr2 && (double) lhs.shr3 == (double) rhs.shr3 && (double) lhs.shr4 == (double) rhs.shr4 && (double) lhs.shr5 == (double) rhs.shr5 && (double) lhs.shr6 == (double) rhs.shr6 && (double) lhs.shr7 == (double) rhs.shr7 && (double) lhs.shr8 == (double) rhs.shr8 && (double) lhs.shg0 == (double) rhs.shg0 && (double) lhs.shg1 == (double) rhs.shg1 && (double) lhs.shg2 == (double) rhs.shg2 && (double) lhs.shg3 == (double) rhs.shg3 && (double) lhs.shg4 == (double) rhs.shg4 && (double) lhs.shg5 == (double) rhs.shg5 && (double) lhs.shg6 == (double) rhs.shg6 && (double) lhs.shg7 == (double) rhs.shg7 && (double) lhs.shg8 == (double) rhs.shg8 && (double) lhs.shb0 == (double) rhs.shb0 && (double) lhs.shb1 == (double) rhs.shb1 && (double) lhs.shb2 == (double) rhs.shb2 && (double) lhs.shb3 == (double) rhs.shb3 && (double) lhs.shb4 == (double) rhs.shb4 && (double) lhs.shb5 == (double) rhs.shb5 && (double) lhs.shb6 == (double) rhs.shb6 && (double) lhs.shb7 == (double) rhs.shb7 && (double) lhs.shb8 == (double) rhs.shb8;
    }

    public static bool operator !=(SphericalHarmonicsL2 lhs, SphericalHarmonicsL2 rhs)
    {
      return !(lhs == rhs);
    }

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void SetZero_Injected(ref SphericalHarmonicsL2 _unity_self);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void AddAmbientLight_Injected(
      ref SphericalHarmonicsL2 _unity_self,
      ref Color color);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void AddDirectionalLightInternal_Injected(
      ref SphericalHarmonicsL2 sh,
      ref Vector3 direction,
      ref Color color);
  }
}
